//
//  UIViewControllerHelper.swift
//  RelationshipIntegration
//
//  Created by iOS-Czz on 2023/11/15.
//

import Foundation
import UIKit

class UIViewControllerHelper {
    
    /// 获取当前显示的 UIViewController
    class func currentViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return currentViewController(base: nav.visibleViewController)
        }
        if let tab = base as? UITabBarController {
            if let selected = tab.selectedViewController {
                return currentViewController(base: selected)
            }
        }
        if let presented = base?.presentedViewController {
            return currentViewController(base: presented)
        }
        return base
    }
}
